package com.binarysoft.service.type;

import com.binarysoft.service.type.Types;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface TypesMapper {
    @Delete({
        "delete from TYPES",
        "where TYPE_ID = #{typeId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String typeId);

    @Insert({
        "insert into TYPES (TYPE_ID, TYPE_NAME, ",
        "TYPE_DESC, PARENT_ID)",
        "values (#{typeId,jdbcType=VARCHAR}, #{typeName,jdbcType=VARCHAR}, ",
        "#{typeDesc,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR})"
    })
    int insert(Types record);

    @InsertProvider(type=TypesSqlProvider.class, method="insertSelective")
    int insertSelective(Types record);

    @Select({
        "select",
        "TYPE_ID, TYPE_NAME, TYPE_DESC, PARENT_ID",
        "from TYPES",
        "where TYPE_ID = #{typeId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="TYPE_ID", property="typeId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="TYPE_NAME", property="typeName", jdbcType=JdbcType.VARCHAR),
        @Result(column="TYPE_DESC", property="typeDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="PARENT_ID", property="parentId", jdbcType=JdbcType.VARCHAR)
    })
    Types selectByPrimaryKey(String typeId);

    @UpdateProvider(type=TypesSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Types record);

    @Update({
        "update TYPES",
        "set TYPE_NAME = #{typeName,jdbcType=VARCHAR},",
          "TYPE_DESC = #{typeDesc,jdbcType=VARCHAR},",
          "PARENT_ID = #{parentId,jdbcType=VARCHAR}",
        "where TYPE_ID = #{typeId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Types record);
}